package guda.house.biz.form.village;

import guda.house.dal.dataobject.VillageDO;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class VillageForm {


    private Long estateId;
    @NotNull(message = "不能为空")
    @Size(min = 1 , max= 20 ,message = "长度在1到20个字符之间")
    private String villageName;
    private Integer streetCode;
    @Size(min = 0 , max= 60 ,message = "长度不能超过60个字符之间")
    private String villageAddr;
    @NotNull(message = "不能为空")
    private Integer villageStatus;
    @NotNull(message = "不能为空")
    private String gmtDelivery;


    public VillageDO toDO() {
        VillageDO villageDO = new VillageDO();
        villageDO.setEstateId(estateId);
        villageDO.setStreetCode(streetCode);
        villageDO.setVillageAddr(villageAddr);
        villageDO.setVillageName(villageName);
        villageDO.setVillageStatus(villageStatus);

        if(StringUtils.hasText(gmtDelivery)){
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date parse = simpleDateFormat.parse(gmtDelivery);
                villageDO.setGmtDelivery(parse);
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }

        }
        return villageDO;
    }

    public String getGmtDelivery() {
        return gmtDelivery;
    }

    public void setGmtDelivery(String gmtDelivery) {
        this.gmtDelivery = gmtDelivery;
    }

    public Long getEstateId() {
        return estateId;
    }

    public void setEstateId(Long estateId) {
        this.estateId = estateId;
    }

    public String getVillageName() {
        return villageName;
    }

    public void setVillageName(String villageName) {
        this.villageName = villageName;
    }

    public Integer getStreetCode() {
        return streetCode;
    }

    public void setStreetCode(Integer streetCode) {
        this.streetCode = streetCode;
    }

    public String getVillageAddr() {
        return villageAddr;
    }

    public void setVillageAddr(String villageAddr) {
        this.villageAddr = villageAddr;
    }

    public Integer getVillageStatus() {
        return villageStatus;
    }

    public void setVillageStatus(Integer villageStatus) {
        this.villageStatus = villageStatus;
    }


}
